AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

function ENT:Initialize()
	self.Entity:SetModel("models/props_lab/tpplugholder_single.mdl")
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	local phys = self.Entity:GetPhysicsObject()  	
	if (phys:IsValid()) then  		
		phys:Wake()  	
	end  
	table.insert(servertable["ship"]["Looter"],self.Entity)
end

function ENT:SpawnFunction( ply, tr )
	if ( !tr.Hit ) then return end
	local SpawnPos = tr.HitPos + tr.HitNormal * 36
	local ent = ents.Create( "Looter" )
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	return ent
end

function ENT:Scan()
	local entis = ents.FindInSphere(self.Entity:GetPos(), 1000 )
	for _,ent in pairs(entis) do 
		if not(ent == self.Entity) then
			if (ent:GetClass( ) == "moneydrop") then
				local ply = player.GetByUniqueID(servertable["entitys"][self.Entity:EntIndex()]["owner"])
				Changemoney (ply,ent.amount)
				local pos = ent:GetPos()									
				local effectdata = EffectData() 
				effectdata:SetStart( self.Entity:GetPos() ) 
				effectdata:SetOrigin( pos ) 
				effectdata:SetScale( 200 ) 
				effectdata:SetMagnitude(39)
				effectdata:SetEntity(ent)
				util.Effect( "ToolTracer", effectdata,true,true )  
				local effectdata = EffectData() 
				effectdata:SetStart( self.Entity:GetPos() ) 
				effectdata:SetOrigin( pos ) 
				effectdata:SetScale( 200 ) 
				effectdata:SetMagnitude(39)
				effectdata:SetEntity(ent)
				util.Effect( "ManhackSparks", effectdata,true,true ) 
				ent:Remove()
			end
		end
	end
end

function ENT:OnTakeDamage(info)
	Shieldhit(info,self.Entity)
end
